//
//  Keyboard.m
//  CocoaSynth
//
//  Created by Jérémy Brault on 12/02/10.
//  Copyright 2010 None. All rights reserved.
//

#import "ModuleKeyboard.h"
#import "System.h"
#import "SampleProtocol.h"
#import "Sample.h"

@implementation ModuleKeyboard

#pragma mark -
#pragma mark Accessors

@synthesize voltage;

#pragma mark -
#pragma mark Memory Management

- (id) init
{
	if (self = [super init]) {
		voltage = kDefaultVoltage;
	}
	
	return self;
}

#pragma mark -
#pragma mark Module

- (void)compute
{
	for (id<PortOutProtocol> portOut in portsOut) {
		if ([portOut isConnected]) {
			// We build the sample
			NSMutableArray* voltages = [[NSMutableArray alloc] init];
			NSUInteger sampleSize = [[System sharedSystem] sampleSize];
			for (int i = 0; i < sampleSize; i++) {
				[voltages addObject:[NSNumber numberWithFloat:voltage]];
			}
			
			// We set the sample as output data
			id<SampleProtocol> sample = [[Sample alloc] initWithVoltages:voltages];
			[portOut setOutputSample:sample];
			
			[voltages release];
			voltages = nil;
			[sample release];
			sample = nil;
		}
	}
}

@end
